<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <p>苹果<i>{{qian}}</i>元一斤，打{{breaks}}折</p>
    <i>输入你要购买的斤数:</i><input type="text" v-model="num">
    <button @click="buy">结账买单</button>
    <div>
      <p>总价：<span>{{total}}</span>元 <i>||</i> 折后价：<span>{{discount}}</span>元 <i>||</i> 省了<span>{{save}}</span>元 </p>
    </div>
  </div>


  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        qian: 10, //多少元一斤
        breaks: 8, // 打几折
        num: 0, // 斤数
        total: 0,  // 总价
        discount: 0, // 折后价
        save: 0   //省了多少钱
      },
      methods: {
        buy() {
          this.total = this.num * this.qian
          this.discount = this.total * (this.breaks / 10)
          this.save = this.total - this.discount
        }
      },


    })
  </script>


</body>

</html>